package com.hyper_yang.algorithmRecord;

import java.util.*;

// leetcode 739 每日温度 【栈】
public class LeetCode_739 {
    public int[] dailyTemperatures(int[] temperatures) {
        Deque<Integer> stack = new ArrayDeque<>();
        int[] res = new int[temperatures.length];
        for (int i = 0; i < temperatures.length; i++) {
            while (!stack.isEmpty() && temperatures[i] > temperatures[stack.peek()]) {
                Integer top = stack.pop();
                res[top] = i - top;
            }
            stack.push(i);
        }
        return res;
    }

    public static void main(String[] args) {
        LeetCode_739 leetCode739 = new LeetCode_739();
        System.out.println(Arrays.toString(leetCode739.dailyTemperatures(new int[]{73, 74, 75, 71, 69, 72, 76, 73})));
        System.out.println(Arrays.toString(leetCode739.dailyTemperatures(new int[]{30, 40, 50, 60})));
        System.out.println(Arrays.toString(leetCode739.dailyTemperatures(new int[]{30, 60, 90})));
    }
}
